package location.township;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

/**
 *
 * @author avbravo
 */
@ManagedBean(name = "location_townshipBeans")
@ViewScoped
public class Beans {

    private Integer id = 0;
    private Integer id_distrito = 0;
    private String nombre = "";
    private location.general.Beans countryBeans = new location.general.Beans();
    private location.province.Beans provinceBeans = new location.province.Beans();
    private location.district.Beans districtBeans = new location.district.Beans();

    public Beans() {
    }

    public Beans(int id, int id_distrito, String nombre) {
        this.id = id;
        this.id_distrito = id_distrito;
        this.nombre = nombre;
    }

    public void clearBeans() {
        this.id = 0;
        this.id_distrito = 0;
        this.nombre = "";
        this.countryBeans.clearBeans();
        this.provinceBeans.clearBeans();
        this.districtBeans.clearBeans();
    }

    /*
     * Metodo para evitar la inyección SQL
     */
    private String strScape(String str) {
        str = str.trim();
        str = str.replace("'", "''");
        str = str.replace("\\", "\\\\");
        return str;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        if (id == null) {
            id = 0;
        }
        this.id = id;
    }

    public Integer getId_distrito() {
        return id_distrito;
    }

    public void setId_distrito(Integer id) {
        if (id == null) {
            id = 0;
        }
        this.id_distrito = id;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = strScape(nombre);
    }

    public location.general.Beans getCountryBeans() {
        return countryBeans;
    }

    public location.province.Beans getProvinceBeans() {
        return provinceBeans;
    }

    public location.district.Beans getDistrictBeans() {
        return districtBeans;
    }
}
